// 获取URL中的参数，并转换为json数据格式
function getParamObj(){
	// 参数字符串
	var paramString = "";
	// 参数对象
	var paramObj = {};
	if(location.search.length>1){
		paramString = location.search.substring(1);

        // 遍历参数对象并进行分解，赋值给参数对象,获取参数值调用paramObj['参数名']
		var paramArr = paramString.split("&");
		for(var i=0;i<paramArr.length;i++){
			paramObj[paramArr[i].split("=")[0]] = paramArr[i].split("=")[1];
            
            // 参数里面有tabIndex的话值恒为0
			if(location.href.indexOf('baoxian-d'+'mzstg1.pa18.com/')>-1){
              if(paramArr[i].split("=")[0]=="tabIndex"){
				paramObj[paramArr[i].split("=")[0]] = "0";
			 }
			}
		}
	}
	return paramObj;
}
// 根据传入URL参数，与参数json进行拼装，并返回转换后的url字符串
function getQueryString(paramObj,hrefString){
	var searchQueryArr=[];
	for(var key in paramObj){
		if(hrefString.indexOf(key+"=")==-1){
			searchQueryArr.push(key+"="+paramObj[key]);
		}
	}
	return searchQueryArr.join("&")
}
// 根据当前页的URL参数，动态改变相应A标签的链接地址
function hrefChange(){
	var aList = document.getElementsByTagName('a');
	var paramObj = getParamObj();
	var param = "",Href="";
	for(var i=0;i<aList.length;i++){
		Href = aList[i].getAttribute('href');		
		if(Href && !/^(javascript|#).*/.test(Href)){
			param = getQueryString(paramObj,Href);
			if(param!=""){
				var innerStr = aList[i].innerHTML;
				if(Href.indexOf('?') != -1){							
				  var hrefArr = Href.split('?');
				   aList[i].setAttribute('href',hrefArr[0] + '?' + param + '&' + hrefArr[1]);							   
				}
				else{
				   Href = /^(\w+\:\/\/)[^\/]+$/.test(Href) ? (Href+"/") : Href;
				   aList[i].setAttribute('href',Href+'?'+param);			  
				}
				aList[i].innerHTML = innerStr;	
			}			
		}
	}                   
}
hrefChange(); 
//if(location.href.indexOf('www.4008000000.com/zaixiangoumai/')==-1){
//hrefChange(); 
//}
